//
//  DemoRotationViewViewController.m
//  DemoRotationView
//
//  Created by duc nguyen van on 8/15/11.
//  Copyright 2011 STU. All rights reserved.
//

#import "DemoRotationViewViewController.h"

@implementation DemoRotationViewViewController
@synthesize lable;

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

-(void)showLabelX:(float)x andY:(float)y{
	NSString *temp =[[NSString alloc] initWithFormat:@" X : %2f - Y %2f",x,y];
	lable.text = temp;
}

-(IBAction)change{
	
}

-(IBAction)rotate{
	static int i = 0;
	v.transform = CGAffineTransformMakeRotation(i++);
}

-(IBAction)increaseX{
	CGPoint p = v.layer.anchorPoint;
	if (p.x < 1 && p.x >0.1) {
		p.x += 0.1;
		v.layer.anchorPoint = p;
	}
	[self showLabelX:p.x andY:p.y];
}
-(IBAction)decreaseX{
	CGPoint p = v.layer.anchorPoint;
	if (p.x < 1 && p.x > 0.1) {
		p.x -= 0.1;
		v.layer.anchorPoint = p;
	}
	[self showLabelX:p.x andY:p.y];
}

-(IBAction)increaseY{
	CGPoint p = v.layer.anchorPoint;
	if (p.y < 1 && p.y >0.1) {
		p.y += 0.1;
		v.layer.anchorPoint = p;
	}
	[self showLabelX:p.x andY:p.y];
}
-(IBAction)decreaseY{
	CGPoint p = v.layer.anchorPoint;
	if (p.y < 1 && p.y >0.1) {
		p.y -= 0.1;
		v.layer.anchorPoint = p;
	}
	[self showLabelX:p.x andY:p.y];
}

-(IBAction)reset{
	v.layer.anchorPoint = CGPointMake(0.5,0.5);
	v.transform = CGAffineTransformMakeRotation(0);
	[self showLabelX:v.layer.anchorPoint.x andY:v.layer.anchorPoint.y];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	v = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 300, 100)];
	v.backgroundColor = [UIColor redColor];
	[self showLabelX:v.layer.anchorPoint.x andY:v.layer.anchorPoint.y];
	[self.view addSubview:v];
	[v release];
}



// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end
